import {defineStore} from 'pinia'

const defaultOption = {
	text: '拼命加载中...请稍等',
	lock: true,
	background: 'rgba(0, 0, 0, 0.4)',
}

const useLoadingStore = defineStore('loading', {
	state: () => ({
		loadingInstance: null  // 保存加载实例
	}),
	actions: {
		show() {
			this.loadingInstance = ElLoading.service(defaultOption)  // 启动加载指示器
		},
		hide() {
			if (this.loadingInstance) {
				this.loadingInstance.close()  // 关闭加载指示器
				this.loadingInstance = null
			}
		},
	},
})

export default useLoadingStore
